package com.hellogood.yaohuo.server.mgr;

import java.util.List;

import org.apache.log4j.Logger;

import com.hellogood.yaohuo.server.dao.factory.DAOFactory;
import com.hellogood.yaohuo.shared.entity.ThForm;
import com.hellogood.yaohuo.shared.exception.DatabaseException;

public class FanchangMgr {
	Logger log = Logger.getLogger(this.getClass());

	public List<ThForm> searchFanchangFormByOrgCodeAndDate(String code, int level, String startDate, String endDate, String rz) {
		if (code.equals("美季")) {
			level = 1;
		}
		if (level == 2) {
			return DAOFactory.getInstance().createThFormDAO().searchThFormByQuyu(code, startDate, endDate, rz);
		} else if (level == 3) {
			return DAOFactory.getInstance().createThFormDAO().searchThForm(code, startDate, endDate, rz);
		} else if (level == 1) {
			return DAOFactory.getInstance().createThFormDAO().searchThFormByQuyu(null, startDate, endDate, rz);
		}
		return null;
	}

	public ThForm getFormDetail(String billNo) {
		return DAOFactory.getInstance().createThFormDAO().getFormByBillNo(billNo);
	}

	public String deleteForm(String billNo) {
		return DAOFactory.getInstance().createThFormDAO().deleteFanchang(billNo);
	}

	public String saveForm(ThForm form, boolean isModify) {
		return DAOFactory.getInstance().createThFormDAO().createTuihuo(form, isModify);
	}

	public String rz(List<String> bills) {
		String result = "";
		try {
			for (String bill : bills) {
				DAOFactory.getInstance().createThFormDAO().rz(bill);
			}
		} catch (DatabaseException e) {
			log.error(e.getMessage());
			e.printStackTrace();
			result = e.getMessage();
		}
		return result;
	}

	public String getLastFcBillNo(String orgCode) {
		return DAOFactory.getInstance().createThFormDAO().getLastThBillNo(orgCode);
	}

}
